package 数组.最大子数组和53;

import utils.Utils;

public class Solution {

    public static int maxSubArray(int[] nums) {
        int res = nums[0];
        int pre = 0;
        for(int x : nums){
            pre = Math.max(pre+x,x);
            res = Math.max(res,pre);
        }

        return res;
    }

    public static void main(String[] args) {
        int[] nums = {-2,1,-3,4,-1,2,1,-5,4};
        Utils.printInt(maxSubArray(nums));
    }
}
